package com.cy.pj.activity.controller;

import com.cy.pj.activity.pojo.Activity;
import com.cy.pj.activity.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author LiuXu
 * @create 2020-07-04 15:31
 */

@Controller
@RequestMapping("/activity/")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @RequestMapping("doFindById")
    public String doFingById(Integer id, Model model) {
        Activity aty = activityService.findById(id);
        model.addAttribute("aty", aty);
        return "forward:doFindActivitys";
    }

    @RequestMapping("doDeleteById")
    public String doDeleteById(Integer id) {
        activityService.deleteById(id);
        return "forward:doFindActivitys";
    }

    @RequestMapping("doSaveActivity")
    public String doSaveActivity(Activity entiry) {
        activityService.saveActivity(entiry);
        return "redirect:doFindActivitys";
    }

    @RequestMapping("doActivityEditUI")
    public String doActivityEditUI() {
        return "activity_edit";
    }

    @RequestMapping("doFindActivitys")
    public String doFindActivitys(Model model) {
        List<Activity> list = activityService.findActivitys();
        model.addAttribute("list", list);
        return "activity";
    }
}
